/*
 * Zombinoes: Peter Mosher, Michael Pitts
 * TCSS 491 - Computational Worlds
 * Project 1
 */

package physics.tree;


/**
 * Instanciates the methods from the AABB Interface.
 * @author Michael Pitts
 * @version Feb 16, 2012
 * @see AABB
 */
public class AABBObject implements AABB {
	
	protected final float[] my_min, my_max;
	
	public AABBObject(final float[] the_min, final float[] the_max) {
		my_min = the_min.clone();
		my_max = the_max.clone();
	}

	@Override public boolean overlap(final AABB the_other) {
		boolean overlap = true;
		int i = 0;
		final float[] other_min = the_other.getMin();
		final float[] other_max = the_other.getMax();
		while (overlap && i < my_min.length) {
			overlap &= my_min[i] <= other_max[i] && other_min[i] <= my_max[i];
			i++;
		}
		return overlap;
	}

	@Override public float[] getMin() {
		return my_min.clone();
	}

	@Override public float[] getMax() {
		return my_max.clone();
	}

	@Override public void setMin(float... the_min) {
		for (int i = 0 ; i < my_min.length; i++) {
			my_min[i] = the_min[i];
		}
	}

	@Override public void setMax(float... the_max) {
		for (int i = 0 ; i < my_max.length; i++) {
			my_max[i] = the_max[i];
		}
	}

}
